package com.lyf.action;

import java.util.List;

import com.lyf.action.base.BaseAction;
import com.lyf.pojo.Employee;
import com.lyf.pojo.Project;
import com.lyf.service.EmployeeService;
import com.lyf.service.ProjectService;
import com.opensymphony.xwork2.Action;

public class EmployeeAction extends BaseAction{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private EmployeeService employeeService;
	private Employee employee;
	private String code;
	
	
	
	private ProjectService projectService;
	private List<Project> projectList;
	
	public String execute(){
		getSession().remove("employee");
		return Action.SUCCESS;
	}
	
	public String login(){
		Employee e = employeeService.login(employee);
		if(e != null){
			getSession().put("employee", e);
			return Action.SUCCESS;
		}else{
			code = "10001";
			return Action.LOGIN;
		}
	}
	
	public String main(){
		//ʹ��list��ʱ��,ע��list����ʱ���Ѿ�����������
		/*Employee e = (Employee) getSession().get("employee");
		projectList = projectService.findAllByEmployeeId(e.getId());*/
		/*projectList = new ArrayList<Project>();
		
		Employee e = (Employee) getSession().get("employee");*/
		//projectService.findAllByEmployeeId(e.getId());
		projectList = projectService.findAll();
		
		//���ֻ����ʾ���û���ص�,forѭ��һ��,��session�е�employee�Ա�һ��,���û��,��removeһ��...
		return Action.SUCCESS;
	}

	
	//set
	public EmployeeService getEmployeeService() {
		return employeeService;
	}
	
	public void setProjectService(ProjectService projectService) {
		this.projectService = projectService;
	}

	//set,get
	public void setEmployeeService(EmployeeService employeeService) {
		this.employeeService = employeeService;
	}
	public Employee getEmployee() {
		return employee;
	}

	public void setEmployee(Employee employee) {
		this.employee = employee;
	}

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public List<Project> getProjectList() {
		return projectList;
	}

	public void setProjectList(List<Project> projectList) {
		this.projectList = projectList;
	}
	
	
	
}
